﻿using Forum.BaseController;
using Forum.Model.Entity.System;
using Forum.Model.QueryFilters;
using Forum.Service.Interface.System;

namespace Forum.Controllers.System
{
    /// <summary>
    /// 菜单
    /// </summary>
    [Route("Api/SysMenu")]
    [ApiExplorerSettings(GroupName = nameof(ApiVersions.System))]
    public class SysMenuController : BaseController<ISysMenuService>
    {

        public SysMenuController(ISysMenuService defaultService, ILogger<BaseController<ISysMenuService>> logger) : base(defaultService, logger)
        {

        }

        /// <summary>
        /// 分页查询菜单
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        public ApiResponsePaged<SYS_MENU> GetPagedList([FromQuery] QueryParameters param)
        {
            var pagedList = DefaultService.GetPagedList(param);
            return new ApiResponsePaged<SYS_MENU>
            {
                msg = "Get Menu list",
                data = pagedList.ToList(),
                total = pagedList.Total,
                haveMore = pagedList.Total > param.Page * param.PageSize
            };
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("[action]")]
        public ApiResponse<List<SYS_MENU>> GetMenuList()
        {
            if (CurrentUser == null)
                return new ApiResponse<List<SYS_MENU>>(DefaultService.GetMenuList(""));

            return new ApiResponse<List<SYS_MENU>>(DefaultService.GetMenuList(CurrentUser.UserId));
        }
    }
}
